home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Leonardo the Inventor
/
Leonardo The Inventor (93026)(Broderbund)(Riverdeep)(2004).iso
/
LEOWINMV
/
DATABASE.DIR
/
00088_Script_Search
< prev
next >
Wrap
Text File
|
1996-03-28
|
7KB
|
217 lines
-- --------------------------------------------------------
-- Handler clickedFindButton is called when the user clicks the find button.
on clickedFindButton
global findButton
if (isEnabled(findButton)) then
doFind line 1 of the text of cast "searchTopic"
else
setSearchMode
end if
end
-- --------------------------------------------------------
-- Handler doFind
on doFind input
global findButton
if isEnabled(findButton) then
clearDatabase
activateButtonKeepActivated(findButton)
findUserTypedTopic input
enableButton(findButton)
end if
end
-- --------------------------------------------------------
-- Handler findUserTypedTopic
on findUserTypedTopic input
global browserTopics, browserTopLine, numVisibleTopics, browserScroll
global numLinesPerBrowserEntry
if inputContainsIllegalChar(input) then
put "illegal character(s)" into field "searchTopic"
set the selstart = 0
set the selEnd = 999
put "" into field "browser"
setSearchSuccessFul(FALSE)
exit
end if
waitCursor
set searchResults = doSearch(input)
normalCursor
if not(voidP(searchResults)) and not (searchResults = "") and not (searchResults = RETURN)then
set browserTopics = searchResults & RETURN
set browserTopLine = 1
moveScrollSquareToMatchText
setBrowserText
setSearchSuccessFul(TRUE)
selectTopic(1)
showSelectedTopic
else
put "No topics found" into field "searchTopic"
set the selstart = 0
set the selEnd = 999
put "" into field "browser"
setSearchSuccessFul(FALSE)
end if
end
-- --------------------------------------------------------
-- Handler doSearch
on doSearch input
-- To speed up the search, treat the cases separately:
-- Case 1: input is empty - do nothing.
if (input = EMPTY) then exit
-- Case 2: input has one word - get existing list
-- of topics that contain the word.
if (the number of words in input = 1) and (not(isIgnorableWord(word 1 of input))) then
set searchResults = searchOneTopic(input)
return searchResults
end if
-- Cast 3: input has more than 1 word including ignorable words.
-- NOTE: cases 3 and 4 were separated to make the code more readable, even though
-- they could have both been contained in one IF/THEN statement.
if (the number of words in input > 1) and (containsIgnorableWords(input)) then
set newInput = removeIgnorableWords(input)
set searchResults = doSearch(newInput)
return searchResults
end if
-- Cast 4: input has more than 1 word and no ignorable words
if (the number of words in input > 1) and not(containsIgnorableWords(input)) then
-- set containingList = the union of topics that contain any input word
set containingList = []
set numTopics = the number of words in input
-- each word they type represents an individually searchable topic
-- each topic must therefore appear in numTopics lists of topics to
-- contain all the words typed. (example: they type "king david" -
-- each topic must contain the words "king" and "david" and must
-- therefore be found in the list of all topics containing "king"
-- and the list of all topics containing "david", for a total of
-- two lists.
repeat with i = 1 to numTopics
set topicsContainingCurrentTopic = searchOneTopic(word i of input)
repeat with j = 1 to the number of lines in topicsContainingCurrentTopic
-- add the field name to the list
add(containingList,line j of topicsContainingCurrentTopic)
end repeat
end repeat
sort(containingList)
-- now, any topic that appears numTopics times in containingList contains
-- all the topics typed.
-- set searchResults = the fields that contain all search words
set searchResults = ""
repeat with i = 1 to count(containingList) - numTopics + 1
set currentTopic = getAt(containingList,i)
set containsAll = TRUE
-- if the next numTopics-1 items in containingList are also currentTopic,
-- the currentTopic appears numTopics times and therefore contains all
-- searched for topics
repeat with j = 1 to numTopics - 1
if not(getAt(containingList,i+j) = currentTopic) then
set containsAll = FALSE
exit repeat
end if
end repeat
if containsAll = TRUE then
put currentTopic & RETURN after searchResults
end if
end repeat
return searchResults
end if
end
-- --------------------------------------------------------
-- Handler isIgnorableWord
on isIgnorableWord whichWord
if (whichWord = "and") or (whichWord = "of") or (whichWord = "the") or (whichWord = "a") or (whichWord = "an") or (whichWord contains "[") or (whichWord = "-") then
return TRUE
else
return FALSE
end if
end
-- --------------------------------------------------------
-- Handler searchOneTopic
on searchOneTopic topic
return getIndexIndexData (topic)
end
-- --------------------------------------------------------
-- Handler containsIgnorableWords
on containsIgnorableWords phrase
repeat with i = 1 to the number of words in phrase
if (isIgnorableWord(word i of phrase)) then
return TRUE
end if
end repeat
return FALSE
end
-- --------------------------------------------------------
-- Handler removeIgnorableWords
on removeIgnorableWords phrase
set newPhrase = ""
repeat with i = 1 to the number of words in phrase
if not(isIgnorableWord(word i of phrase)) then
set newPhrase = addWordToString(word i of phrase,newPhrase)
end if
end repeat
return newPhrase
end
-- --------------------------------------------------------
-- Handler addWordToString
on addWordToString whichWord, phrase
if (phrase = EMPTY) then
return whichWord
else
return phrase && whichWord
end if
end
-- --------------------------------------------------------
-- Handler setSearchSuccessFul
on setSearchSuccessFul val
global searchSuccessFul
set searchSuccessFul = val
end
-- --------------------------------------------------------
-- Handler inputContainsIllegalChar
on inputContainsIllegalChar input
return (input contains "[") or (input contains "]") or (input contains "{") or (input contains "}") or (input contains "(") or (input contains ")")
end
on isNumber whichWord
return not(voidP(value(whichWord)))
end